﻿@model IEnumerable<BookClubPortal.Models.Book>
@{
    var grid = new WebGrid(Model, defaultSort: "Name", canPage: true, rowsPerPage: 10);
}
@helper Truncate(string
input, int length)
    {
        if(input!=null)
        {
        
             if (input.Length <= length)
             {
                @input
             }
             else
             {
                @input.Substring(0, length)<text>...</text>
             }
        }
} 
@{
    ViewBag.Title = "Browse";
}
<h2>
    Browse books</h2>

<p>
 @using (Html.BeginForm("Index","Browse",FormMethod.Get)){     
         <p> 
                  
           Title: @Html.TextBox("TitleString","", new { style = "width: 150px; height: 30px;" })
           Author: @Html.TextBox("AuthorString","", new { style = "width: 150px; height: 30px;" })
           Genre: @Html.DropDownList("bookGenre", "All")                
         <input type="submit" value="Filter" style="margin-left: 10px;"/> 
         </p>
     
 } 
</p>
@grid.GetHtml(columns: grid.Columns(

    grid.Column("ImageURL", header: "Image", format: @<text><a href="@item.ImageURL" target="_blank"><img src="@item.ImageURL" alt="@item.Title" onerror="AltImage(this,'@Url.Content("~/Content/Images/logo.png")')" width="50" height="50"></a></text>),
    grid.Column("Title", format: @<text>@Truncate(@item.Title, 30)</text>),
    grid.Column("Author", format: @<text>@Truncate(@item.Author, 30)</text>),
    grid.Column("ReleaseYear", header: "Release Year"),
    grid.Column("Genre.Name", header: "Genre", format: @<text>@Truncate(@item.Genre.Name, 30)</text>),
    grid.Column("DescriptionURL", header: "Description", format: @<text>@Truncate(@item.Description, 30)</text>),
    grid.Column(columnName: "Actions",
                    format: (book) =>
                    {
                        var links = @Html.ActionLink("Buy", "Buy", new { id = book.BookId }) + "|" +
                        @Html.ActionLink("Details", "Details", new { id = book.BookId });
                        return Html.Raw(links);
                    }
                            ))
                        )
@section Scripts {
    @Scripts.Render("~/bundles/tools")
}
